
package com.bluelinelabs.conductor.demo.controllers;

import ohos.agp.animation.AnimatorGroup;
import ohos.agp.animation.AnimatorProperty;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;

/**
 * lipeiquan
 *
 * @since 2021-05-06
 */
public class CircularRevealChangeHandlerCompat extends CircularRevealChangeHandler {
    public CircularRevealChangeHandlerCompat() {
    }

    public CircularRevealChangeHandlerCompat(Component fromView, Component containerView) {
        super(fromView, containerView);
    }

    @Override
    protected AnimatorGroup getAnimator(ComponentContainer container, Component from, Component to, boolean isPush, boolean toAddedToContainer) {
        AnimatorGroup animatorGroup = new AnimatorGroup();
        AnimatorProperty fromAnimatorProperty = null;
        AnimatorProperty toAnimatorProperty = null;
        if (to != null) {
            float start = toAddedToContainer ? 0 : to.getAlpha();
            toAnimatorProperty = to.createAnimatorProperty();
            toAnimatorProperty.alphaFrom(start).alpha(1);
        }

        if (from != null && (!isPush || removesFromViewOnPush())) {
            fromAnimatorProperty = from.createAnimatorProperty();
            fromAnimatorProperty.alpha(0);
        }

        if (fromAnimatorProperty != null && toAnimatorProperty != null) {
            animatorGroup.runParallel(fromAnimatorProperty, toAnimatorProperty);
        } else if (fromAnimatorProperty != null) {
            animatorGroup.runParallel(fromAnimatorProperty);
        } else if (toAnimatorProperty != null) {
            animatorGroup.runParallel(toAnimatorProperty);
        }

        return animatorGroup;
//        return super.getAnimator(container, from, to, isPush, toAddedToContainer);
    }
}
